Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add AES_CBC to crypto module of Berry #19964

Merged
merged 1 commit into from
Nov 9, 2023
Merged

Conversation

Staars
Copy link
Contributor

@Staars Staars commented Nov 9, 2023

Description:

Adds CBC mode to AES crypto functions in Berry (needed for Tuya BLE).
Follows the naming conventions of 'encrypt1' and 'decrypt1' of the CCM mode.
Not active by default, activate with -DUSE_BERRY_CRYPTO_AES_CBC=1 in build env.
Test example:

var b = bytes().fromstring("hello world_____") # 16-byte aligned
var key = bytes().fromstring("1122334455667788") # 16 bytes
var iv = bytes().fromstring("8877665544332211") # 16 bytes

print("data:",b.asstring())
import crypto
aes = crypto.AES_CBC()
aes.encrypt1(key, iv, b)
print("cipher:",b)
iv = bytes().fromstring("8877665544332211")
aes.decrypt1(key, iv, b)
print("decrypted data:",b.asstring())

Test with comparable Python example:

from Crypto.Cipher import AES
import binascii

def decrypt(data, iv, key):
    cipher = AES.new(key, AES.MODE_CBC, iv)
    return cipher.decrypt(data)


def encrypt(data, iv, key):
    cipher = AES.new(key, AES.MODE_CBC, iv)
    return cipher.encrypt(data)

data = "hello world_____".encode('utf-8') # "padded" with __ to 16 byte
key = "1122334455667788".encode('utf-8') # 16-byte
iv = "8877665544332211".encode('utf-8')  # 16-byte

print(data)
cipher = encrypt(data,iv,key)
print(binascii.hexlify(cipher))
decrypted = decrypt(cipher,iv,key)
print(decrypted)

Checklist:

  • The pull request is done against the latest development branch
  • Only relevant files were touched
  • Only one feature/fix was added per PR and the code change compiles without warnings
  • The code change is tested and works with Tasmota core ESP8266 V.2.7.4.9
  • The code change is tested and works with Tasmota core ESP32 V.2.0.14
  • I accept the CLA.

NOTE: The code change must pass CI tests. Your PR cannot be merged unless tests pass

@s-hadinger s-hadinger merged commit cf6de0c into arendst:development Nov 9, 2023
64 checks passed
@Staars Staars deleted the aes_cbc branch November 27, 2023 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants